package com.ruoyi.yljf.controller.AdminController;

import java.util.List;
import java.util.Arrays;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.yljf.domain.vo.BookChapterVO;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.yljf.domain.BookChapter;
import com.ruoyi.yljf.service.IBookChapterService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 章节内容Controller
 * 
 * @author metaee
 * @date 2025-02-12
 */
@RestController
@RequestMapping("/ yljf/chapter")
public class BookChapterController extends BaseController {
    @Autowired
    private IBookChapterService bookChapterService;

    /**
     * 查询章节内容列表
     */
    @PreAuthorize("@ss.hasPermi(' yljf:chapter:list')")
    @GetMapping("/list")
    public TableDataInfo list(BookChapter bookChapter) {
        startPage();
        List<BookChapterVO> list = bookChapterService.selectBookChapterList(bookChapter);
        return getDataTable(list);
    }

    /**
     * 导出章节内容列表
     */
    @PreAuthorize("@ss.hasPermi(' yljf:chapter:export')")
    @Log(title = "章节内容", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BookChapter bookChapter) {
        List<BookChapterVO> list = bookChapterService.selectBookChapterList(bookChapter);
        ExcelUtil<BookChapterVO> util = new ExcelUtil<BookChapterVO>(BookChapterVO.class);
        util.exportExcel(response, list, "章节内容数据");
    }

    /**
     * 获取章节内容详细信息
     */
    @PreAuthorize("@ss.hasPermi(' yljf:chapter:query')")
    @GetMapping(value = "/{chapterId}")
    public AjaxResult getInfo(@PathVariable("chapterId") Long chapterId) {
        return success(bookChapterService.getById(chapterId));
    }

    /**
     * 新增章节内容
     */
    @PreAuthorize("@ss.hasPermi(' yljf:chapter:add')")
    @Log(title = "章节内容", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BookChapter bookChapter) {
        return toAjax(bookChapterService.save(bookChapter));
    }

    /**
     * 修改章节内容
     */
    @PreAuthorize("@ss.hasPermi(' yljf:chapter:edit')")
    @Log(title = "章节内容", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BookChapter bookChapter) {
        return toAjax(bookChapterService.updateById(bookChapter));
    }

    /**
     * 删除章节内容
     */
    @PreAuthorize("@ss.hasPermi(' yljf:chapter:remove')")
    @Log(title = "章节内容", businessType = BusinessType.DELETE)
	@DeleteMapping("/{chapterIds}")
    public AjaxResult remove(@PathVariable Long[] chapterIds) {
        return toAjax(bookChapterService.removeByIds(Arrays.asList(chapterIds)));
    }
}
